<template>
    <div class="theme-toggle-container">
       
    </div>
</template>

<script>
export default {
    name: 'ThemeToggle',
    data() {
        return {
            isDarkMode: false
        };
    },
    mounted() {
        // 从localStorage加载主题设置
        this.loadTheme();
        // 应用初始主题
        this.applyTheme();
        // 监听EAA组件的主题切换事件
        this.$root.$on('theme-changed', this.onThemeChanged);
    },
    beforeDestroy() {
        // 移除事件监听
        this.$root.$off('theme-changed', this.onThemeChanged);
    },
    methods: {
        // 切换主题
        toggleTheme() {
            this.isDarkMode = !this.isDarkMode;
            this.applyTheme();
            this.saveTheme();
            this.$message.success(this.isDarkMode ? '已切换到暗模式' : '已切换到亮模式');
        },

        // 应用主题
        applyTheme() {
            const body = document.body;
            const html = document.documentElement;
            
            if (this.isDarkMode) {
                body.classList.add('theme-dark');
                html.classList.add('theme-dark');
            } else {
                body.classList.remove('theme-dark');
                html.classList.remove('theme-dark');
            }
        },

        // 保存主题设置到localStorage
        saveTheme() {
            localStorage.setItem('app-theme', this.isDarkMode ? 'dark' : 'light');
        },

        // 从localStorage加载主题设置
        loadTheme() {
            const savedTheme = localStorage.getItem('app-theme');
            if (savedTheme) {
                this.isDarkMode = savedTheme === 'dark';
            } else {
                // 如果没有保存的设置，默认使用亮模式，确保第一次打开显示"Dark Mode"按钮
                this.isDarkMode = false;
            }
        },

        // 监听EAA组件的主题切换事件
        onThemeChanged(isDarkMode) {
            this.isDarkMode = isDarkMode;
            this.saveTheme();
        }
    }
};
</script>

<style lang="less" scoped>
.theme-toggle-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid #ddd;
    border-radius: 25px;
    background: #fff;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-width: 100px;
    justify-content: center;
    
    &:hover {
        background: #f8f9fa;
        border-color: @blueColor;
        color: @blueColor;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    &.theme-toggle-dark {
        background: #2c2c2c;
        border-color: #444;
        color: #fff;
        
        &:hover {
            background: #444;
            border-color: #666;
        }
    }
    
    i {
        font-size: 16px;
    }
    
    .theme-toggle-text {
        font-weight: 500;
    }
}

// 响应式设计
@media (max-width: 768px) {
    .theme-toggle-container {
        top: 10px;
        right: 10px;
    }
    
    .theme-toggle-btn {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 80px;
        
        .theme-toggle-text {
            display: none;
        }
    }
}
</style>
